<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="人员编号" prop="pin">
      <el-input v-model="dataForm.pin" placeholder="人员编号"></el-input>
    </el-form-item>
    <el-form-item label="名称 " prop="name">
      <el-input v-model="dataForm.name" placeholder="名称 "></el-input>
    </el-form-item>
    <el-form-item label="湿度" prop="humidity">
      <el-input v-model="dataForm.humidity" placeholder="湿度"></el-input>
    </el-form-item>
    <el-form-item label="人员所属部门编号(更新可以不填，新增必填)" prop="deptnumber">
      <el-select v-model="dataForm.deptnumber" clearable placeholder="人员所属部门编号(更新可以不填，新增必填)">
        <el-option
          v-for="item in deptList"
          :key="item.deptnumber"
          :label="item.deptname"
          :value="item.deptnumber">
        </el-option>
      </el-select>
    </el-form-item>
    <el-form-item label="办公电话" prop="telephone">
      <el-input v-model="dataForm.telephone" placeholder="办公电话"></el-input>
    </el-form-item>
    <el-form-item label="手机号" prop="mobile">
      <el-input v-model="dataForm.mobile" placeholder="手机号"></el-input>
    </el-form-item>
    <el-form-item label="性别" prop="gender">
      <el-input v-model="dataForm.gender" placeholder="性别 。M表示男,F表示女"></el-input>
    </el-form-item>
    <el-form-item label="邮箱" prop="email">
      <el-input v-model="dataForm.email" placeholder="邮箱"></el-input>
    </el-form-item>
    <el-form-item label="身份证号" prop="identitycard">
      <el-input v-model="dataForm.identitycard" placeholder="身份证号"></el-input>
    </el-form-item>
    <el-form-item label="卡号" prop="cardno">
      <el-input v-model="dataForm.cardno" placeholder="卡号"></el-input>
    </el-form-item>
    <el-form-item label="职务编号" prop="position">
      <el-input v-model="dataForm.position" placeholder="职务编号"></el-input>
    </el-form-item>
    <el-form-item label="归属区域编号" prop="zonecode">
      <el-input v-model="dataForm.zonecode" placeholder="归属区域编号"></el-input>
    </el-form-item>
    <el-form-item label="出生日期" prop="birthday">
      <el-input v-model="dataForm.birthday" placeholder="出生日期。格式为%Y-%m-%d"></el-input>
    </el-form-item>
    <el-form-item label="雇佣日期" prop="hiredday">
      <el-input v-model="dataForm.hiredday" placeholder="雇佣日期。格式为%Y-%m-%d"></el-input>
    </el-form-item>
    <el-form-item label="试用开始日期" prop="trialstarttime">
      <el-input v-model="dataForm.trialstarttime" placeholder="试用开始日期。格式为%Y-%m-%d"></el-input>
    </el-form-item>
    <el-form-item label="试用结束日期" prop="trialendtime">
      <el-input v-model="dataForm.trialendtime" placeholder="试用结束日期。格式为%Y-%m-%d"></el-input>
    </el-form-item>
    <el-form-item label="合同开始日期" prop="contractstarttime">
      <el-input v-model="dataForm.contractstarttime" placeholder="合同开始日期。格式为%Y-%m-%d"></el-input>
    </el-form-item>
    <el-form-item label="学历类型" prop="educational">
      <el-input v-model="dataForm.educational" placeholder="学历类型0表示为中专1 表示为高中2 表示为专科3 表示为本科4 表示为研究生5 表示为博士生允许值: 0, 1, 2, 3, 4, 5"></el-input>
    </el-form-item>
    <el-form-item label="上班签到" prop="inlate">
      <el-input v-model="dataForm.inlate" placeholder="0 表示为依据对应时间段1 上班必须签到2 上班不用签到允许值: 0, 1, 2"></el-input>
    </el-form-item>
    <el-form-item label="下班签退" prop="outearly">
      <el-input v-model="dataForm.outearly" placeholder="下班签退0 表示为依据对应时间段1 下班必须签到2 下班不用签到允许值: 0, 1, 2"></el-input>
    </el-form-item>
    <el-form-item label="地址" prop="address">
      <el-input v-model="dataForm.address" placeholder="地址"></el-input>
    </el-form-item>
    <el-form-item label="民族" prop="national">
      <el-input v-model="dataForm.national" placeholder="民族"></el-input>
    </el-form-item>
    <el-form-item label="雇佣类型" prop="hiretype">
      <el-input v-model="dataForm.hiretype" placeholder="雇佣类型0 表示合同工1 表示兼职2 表示临时工允许值: 0, 1, 2"></el-input>
    </el-form-item>
    <el-form-item label="人员自助密码" prop="selfpassword">
      <el-input v-model="dataForm.selfpassword" placeholder="人员自助密码。长度为1~20个字符"></el-input>
    </el-form-item>
    <el-form-item label="人员是否考勤" prop="att">
      <el-input v-model="dataForm.att" placeholder="人员是否考勤1 表示为是0表示为否允许值: 0, 1"></el-input>
    </el-form-item>
    <el-form-item label="验证方式" prop="comverifys">
      <el-input v-model="dataForm.comverifys" placeholder="验证方式 (详见更新人员功能介绍附录1：人员验证方式表)"></el-input>
    </el-form-item>
    <el-form-item label="比对照片信息" prop="enrollpic">
      <el-input v-model="dataForm.enrollpic" placeholder="比对照片信息，BASE64格式"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()" v-if="canSubmit">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
    import {getObj, addObj, putObj,getDept} from '@/api/hik/cdcpeople'

    export default {
    data () {
      return {
        visible: false,
        canSubmit: false,
        deptList:[],
        dataForm: {
          id: 0,
          pin: '',

          name: '',

          humidity: '',

          deptnumber: '',

          telephone: '',

          mobile: '',

          gender: '',

          email: '',

          identitycard: '',

          cardno: '',

          position: '',

          zonecode: '',

          birthday: '',

          hiredday: '',

          trialstarttime: '',

          trialendtime: '',

          contractstarttime: '',

          educational: '',

          inlate: '',

          outearly: '',

          address: '',

          national: '',

          hiretype: '',

          selfpassword: '',

          att: '',

          comverifys: '',

          enrollpic: '',

          createTime: '',

          updateTime: '',

          updateBy: '',

          delFlag: '',

        },
        dataRule: {
          pin: [
            { required: true, message: '人员编号不能为空', trigger: 'blur' }
          ],

        }
      }
    },
    methods: {
      init (id) {
        getDept(this.dataForm.id).then(response => {
          console.log(response);
          this.deptList = response.data.data
        })
        this.dataForm.id = id || 0;
        this.visible = true;
        this.canSubmit = true;
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            getObj(this.dataForm.id).then(response => {
                this.dataForm = response.data.data
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.canSubmit = false;
            if (this.dataForm.id) {
                putObj(this.dataForm).then(data => {
                    this.$notify.success('修改成功')
                    this.visible = false
                    this.$emit('refreshDataList')
                }).catch(() => {
                    this.canSubmit = true;
                });
            } else {
                addObj(this.dataForm).then(data => {
                    this.$notify.success('添加成功')
                    this.visible = false
                    this.$emit('refreshDataList')
                }).catch(() => {
                    this.canSubmit = true;
                });
            }
          }
        })
      }
    }
  }
</script>
